﻿using System;
using System.Linq.Expressions;

namespace FT.Architecture.Queries
{
    public class SortClauseItem<T>
    {
        private SortOrder sortOrder;
        private readonly Expression<Func<T, object>> sortMember;
        private readonly SortClause<T> clause;

        internal SortClauseItem(Expression<Func<T, object>> sortMember, SortClause<T> clause)
        {
            this.sortOrder = SortOrder.Ascending;
            this.sortMember = sortMember;
            this.clause = clause;
        }

        internal SortClauseItem(Expression<Func<T, object>> sortMember, SortOrder order, SortClause<T> clause)
        {
            this.sortOrder = order;
            this.sortMember = sortMember;
            this.clause = clause;
        }

        public SortOrder SortOrder
        {
            get
            {
                return sortOrder;
            }
        }

        public Expression<Func<T, object>> SortMember
        {
            get
            {
                return sortMember;
            }
        }

        public SortClause<T> Ascending()
        {
            sortOrder = SortOrder.Ascending;
            return clause;
        }

        public SortClause<T> Descending()
        {
            sortOrder = SortOrder.Descending;
            return clause;
        }
    }
}
